package com.mallcai.bigdata.ladon.dpl.mapper.system;

import com.mallcai.bigdata.ladon.dpl.entity.system.Role;
import com.mallcai.bigdata.ladon.dpl.mapper.system.provider.RoleSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface RoleMapper {

    @InsertProvider(type = RoleSqlProvider.class, method = "insert")
    public int insert(Role role);

    @UpdateProvider(type = RoleSqlProvider.class, method = "update")
    public int update(Role role);

    @UpdateProvider(type = RoleSqlProvider.class, method = "delete")
    public int delete(Role role);

    @SelectProvider(type = RoleSqlProvider.class, method = "getByParams")
    public List<Role> getByParams(@Param("params") Map<String, Object> params);

    @Select({
            "SELECT id, name, code, type FROM " + RoleSqlProvider.TB_ROLE + " WHERE archive = 0"
    })
    public List<Role> getAllRoles();

    @Select({
            "SELECT * FROM " + RoleSqlProvider.TB_ROLE
                    + " WHERE archive = 0 AND code = #{code} OR name =#{name}"
    })
    public List<Role> hasSame(@Param("code") String code, @Param("name") String name);
}
